# -*- coding: utf-8 -*-

import json


class NetAdapter(object):

    def __init__(self):
        pass

    def handle_data(self, handler, data):
        pass


class EventType(object):
    INIT = 'init'
    DATA = 'data'


class MsgCtx(object):

    def __init__(self, cmd=EventType.DATA, data=None):
        self.cmd = cmd
        self.data = data

    def to_json(self):
        _dict = dict()
        _dict['cmd'] = self.cmd
        _dict['data'] = self.data
        return json.dumps(_dict)

    @staticmethod
    def ctx_from_json(json_str):
        _dict = json.loads(json_str)
        if _dict is None:
            return None
        return MsgCtx(cmd=_dict.get('cmd'), data=_dict.get('data'))

    def __repr__(self):
        return self.to_json()

    __str__ = __repr__
